import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OpenTwoRouter } from '../Common/options'
import { winningBidder, ProjectList, IdentityLevel, EnumComments } from '../Common/Conversion'

const { hostname } = window.location

const projectUuidStatus = ['jtgj.ljkjkf.com']
const winningBidderUuidStatus = [
    'bada.ljkjkf.com',
    'jtgj.ljkjkf.com',
    'mutishiyanshi.admin.ljkjkf.com',
    'longdu.ljkjkf.com',
]
const organizationTypeStatus = ['jtgj.ljkjkf.com']
const amountStatus = ['bada.ljkjkf.com', 'jtgj.ljkjkf.com', 'mutishiyanshi.admin.ljkjkf.com', 'longdu.ljkjkf.com']
const planBitulithStatus = ['bada.ljkjkf.com', 'jtgj.ljkjkf.com', 'mutishiyanshi.admin.ljkjkf.com', 'longdu.ljkjkf.com']
const planCementConcreteStatus = [
    'bada.ljkjkf.com',
    'jtgj.ljkjkf.com',
    'mutishiyanshi.admin.ljkjkf.com',
    'longdu.ljkjkf.com',
]

export const Organization = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    let data = {
        type: '系统设置',
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission?.findIndex(v => v.uuid === 'd13a399d-fc07-4586-bfec-c29ca4b496cb') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增组织机构" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            {
                ...commonTableList.projectUuid,
                valueEnum: await ProjectList(),
                width: 300,
                hideInAdded: projectUuidStatus.includes(hostname),
                hideInModify: projectUuidStatus.includes(hostname),
                hideInTable: projectUuidStatus.includes(hostname),
                hideInSearch: projectUuidStatus.includes(hostname),
            },
            { ...commonTableList.code, rules: true, title: '编号' },
            { ...commonTableList.tableName, title: '简称' },
            { ...commonTableList.fullName, hideInSearch: true },
            {
                dataIndex: 'winningBidderUuid',
                title: '中标单位',
                valueType: 'select',
                valueEnum: await winningBidder(),
                ellipsis: true,
                width: 150,
                hideInAdded: winningBidderUuidStatus.includes(hostname),
                hideInModify: winningBidderUuidStatus.includes(hostname),
                hideInTable: winningBidderUuidStatus.includes(hostname),
                hideInSearch: winningBidderUuidStatus.includes(hostname),
            },
            { ...commonTableList.sortId, rules: true, hideInSearch: true },
            {
                dataIndex: 'organizationType',
                title: '组织机构类型',
                valueType: 'select',
                valueEnum: await EnumComments('organizationType'),
                width: 150,
                hideInAdded: !organizationTypeStatus.includes(hostname),
                hideInModify: !organizationTypeStatus.includes(hostname),
                hideInTable: !organizationTypeStatus.includes(hostname),
                hideInSearch: !organizationTypeStatus.includes(hostname),
            },
            {
                dataIndex: 'identityLevel',
                title: '身份',
                valueType: 'select',
                valueEnum: await IdentityLevel(),
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'amount',
                title: '产值',
                valueType: 'inputNumber',
                rules: true,
                width: 150,
                hideInAdded: amountStatus.includes(hostname),
                hideInModify: amountStatus.includes(hostname),
                hideInTable: amountStatus.includes(hostname),
                hideInSearch: amountStatus.includes(hostname),
            },
            {
                dataIndex: 'planBitulith',
                title: '沥青计划产量(kg)',
                valueType: 'inputNumber',
                rules: true,
                width: 150,
                hideInAdded: planBitulithStatus.includes(hostname),
                hideInModify: planBitulithStatus.includes(hostname),
                hideInTable: planBitulithStatus.includes(hostname),
                hideInSearch: true,
            },
            {
                dataIndex: 'planCementConcrete',
                title: '水泥计划产量(m³)',
                valueType: 'inputNumber',
                rules: true,
                width: 150,
                hideInAdded: planCementConcreteStatus.includes(hostname),
                hideInModify: planCementConcreteStatus.includes(hostname),
                hideInTable: planCementConcreteStatus.includes(hostname),
                hideInSearch: true,
            },

            commonTableList.remark,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 320,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === '5e3d8e1c-8ef7-437e-a62f-9c1d8a9eb9b5') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '162a5706-5047-4314-b9fb-20374461681f') !== -1 && (
                            <OpenTwoRouter
                                key="TwoOne"
                                title="从属机构"
                                twoTitle="管理下属组织机构"
                                modal="TableList"
                                OptionsEvent={OptionsEvent}
                                other={{
                                    page: 'Organization',
                                    Permission,
                                    oneData: record,
                                    header: data.columns,
                                }}
                            />
                        ),
                        <OpenTwoRouter
                            key="two"
                            title="固定数据"
                            twoTitle="机构信息固定数据"
                            modal="EditTableModal"
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'OrganizationCustomData',
                                actionRef,
                                Permission,
                                oneData: record,
                                header: data.columns,
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === 'cbe36d41-d603-4516-a82c-25a38881dee5') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="delete"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
